package com.example.springbootdemo.dto;

import com.example.springbootdemo.validation.ValidCharset;
import com.example.springbootdemo.validation.ValidEpsg;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;
import java.util.Objects;

@Data
@NoArgsConstructor(force = true) // 强制生成无参构造器但设为私有
public class GeoJsonDto {
    @NotNull(message = "geoJson cannot be null")
    private final String geoJson;

    @ValidEpsg
    private final String epsg;

    @ValidCharset
    private final String charset;

    @JsonCreator
    public GeoJsonDto(
            @JsonProperty(value = "geoJson", required = true) String geoJson,
            @JsonProperty(value = "epsg") String epsg,
            @JsonProperty(value = "charset") String charset
    ) {
        this.geoJson = Objects.requireNonNull(geoJson);
        this.epsg = StringUtils.hasText(epsg) ? epsg : "EPSG:4326";
        this.charset = StringUtils.hasText(charset) ? charset : "UTF-8";
    }
}
